var app = getApp();
Page({
  data: {
    section: [{
      name: '广告收益',
      typeId: '1'
    }, {
        name: '酒妹饭票收益',
      typeId: '2'
    }
    ],
    currentId: '1',
    zd_price:''
  },

  onLoad: function() {

  },

  onShow:function(){
    var store_id = wx.getStorageSync("store_id");
    console.log(store_id)
    if(!store_id){
      app.showToast("请登录小程序")
      wx.navigateBack();
    }else{
      this.setData({
        store_id:wx.getStorageSync("store_id")
      })
      this.getWithdrawalStatistics();
    }
  },

  getWithdrawalStatistics:function(){
    var t = this;
    app.visit("account/getWithdrawalStatistics", {
      store_id:t.data.store_id
    }, "", function(c) {
      console.log(c)
      if(0 == c.code){
        t.setData({
          info:c.data
        })
      }else{
        app.showToast(c.msg)
      }
    })
  },

  handleTap: function (e) {
    var id = e.currentTarget.id;
    this.setData({
      currentId: id,
      zd_price:''
    })
  },

  setPrice:function(e){
    var zd_price = e.detail.value;
    console.log(zd_price)
    this.setData({
      zd_price:zd_price
    })
  },

  getAll:function(){
    var currentId = this.data.currentId;
    var zd_price = 0;
    if(currentId == 1){
      zd_price = this.data.info.ktx_price;
    }else if(currentId == 2){
      zd_price = this.data.info.fp_price;
    }
    this.setData({
      zd_price:zd_price
    })
  },

  tijiao:function(){
    var t = this;
    var currentId = t.data.currentId;
    var zd_price = t.data.zd_price;
    var info = t.data.info;
    if(!zd_price || zd_price < 0){
      app.showToast("请输入提现金额")
    }else if((!(/(^[0-9]+(.[0-9]{1,3})?$)/.test(zd_price)))){
      app.showToast("输入金额格式不正确")
    }else{
      if(currentId == 1){
        if(zd_price > Number(info.ktx_price)){
          app.showToast("可提现金额不足")
          return;
        }
      }else if(currentId == 2){
        if(zd_price > Number(info.fp_price)){
          app.showToast("可提现金额不足")
          return;
        }
      }
      app.visit("account/setTiXianLog", {
        store_id:t.data.store_id,
        currentId:currentId,
        zd_price:zd_price
      }, "", function(c) {
        console.log(c)
        if(0 == c.code){
          app.showToast("提现申请成功")
        }else{
          app.showToast(c.msg)
        }
      })
    }
  },

  tx_info: function (e) {
    var currentId = this.data.currentId;
    if(currentId==1){
      wx.navigateTo({
        url: 'tx_info'
      });
    }else{
      wx.navigateTo({
        url: 'txfp_info'
      });
    }
  },

  tixianxinxi:function(e){
    wx.navigateTo({
      url: 'tixianxinxi'
    });
  }

})